package chapter20_Annotations;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Date: 2019/2/15
 * Time: 14:36
 * User: Driss.
 * Description:一个简单的注解处理器，用它来读取PasswordUtils类，并使用反射机制查找@UseCase标记
 */
public class UseCaseTracker {
    public static void trackUseCases(List<Integer> useCases, Class<?> cl){
        for(Method method : cl.getDeclaredMethods()){
            UseCase uc = method.getAnnotation(UseCase.class);
            if(uc != null){
                System.out.println("Found UseCase ：" + uc.id() + " " + uc.description());
                useCases.remove(new Integer(uc.id()));
            }
        }

        for(int i : useCases){
            System.out.println("Warning : Missing use case-" + i);
        }
    }

    public static void main(String[] args) {
        ArrayList<Integer> useCases = new ArrayList<Integer>();
        Collections.addAll(useCases,47,48,49,50);
        trackUseCases(useCases,PasswordUtils.class);
    }
}
